package util.enumhelper;

import entity.FnBBranchEntity;
import entity.FnBReservationEntity;
import entity.ReservedMealEntity;
import entity.ReservedSetMealEntity;


public class ReservationHelper {
    private FnBReservationEntity reservation;
    private FnBBranchEntity branch;
    private Double pointReceived;
    
    public ReservationHelper() {     
    }
    
    public ReservationHelper(FnBReservationEntity reservation, FnBBranchEntity branch) {
        this.reservation = reservation;
        this.branch = branch;
        calculate();
    }
     
    public FnBReservationEntity getReservation() {
        return reservation;
    }

    public void setReservation(FnBReservationEntity reservation) {
        this.reservation = reservation;
    }

    public Double getPointReceived() {
        return pointReceived;
    }

    public void setPointReceived(Double pointReceived) {
        this.pointReceived = pointReceived;
    }
    
    // Support method to calculate the number of point stemming from the reservation
    private void calculate() {
        double point = 0;
        double billValue = 0;
        if (reservation instanceof FnBReservationEntity) {
            FnBReservationEntity fnBReservation = (FnBReservationEntity) reservation;
            for (ReservedSetMealEntity obj: fnBReservation.getReservedSetMeal()) {
                point = point + obj.getPointReceived()*obj.getQuantity();
            }
            for (ReservedMealEntity obj: fnBReservation.getReservedMeal()) {
                point = point + obj.getPointReceived()*obj.getQuantity();
                billValue = billValue + obj.getPrice()*obj.getQuantity();
            }
        }
        setPointReceived(point);
    }

    public FnBBranchEntity getBranch() {
        return branch;
    }

    public void setBranch(FnBBranchEntity branch) {
        this.branch = branch;
    }
}
